package com.atguigu.rabbitmq.producer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqTopicExchangeConfiguration {

    // 声明交换机
    @Bean
    public Exchange topicExchange() {
        return ExchangeBuilder.topicExchange("topic_exchange").durable(true).build();
    }

    // 声明队列
    @Bean
    public Queue topicQueue01() {
        return QueueBuilder.durable("topic_queue_01").build();
    }

    // 声明队列
    @Bean
    public Queue topicQueue02() {
        return QueueBuilder.durable("topic_queue_02").build();
    }

    // 声明队列和交换机的绑定信息 topic_exchange 匹配类型为 中间有orange类型的
    @Bean
    public Binding topicQueue01Binding() {
        return BindingBuilder.bind(topicQueue01()).to(topicExchange())
                .with("*.orange.*").noargs();
    }

    // 声明队列和交换机的绑定信息 topic_exchange 匹配类型为 中间有前面有两段 后缀为rabbit类型的
    @Bean
    public Binding topicQueue02BindingErrorRoutingKey() {
        return BindingBuilder.bind(topicQueue02()).to(topicExchange())
                .with("*.*.rabbit").noargs();
    }
    // 声明队列和交换机的绑定信息 topic_exchange 匹配类型为  开头为lazy. 后面任何数类型的
    @Bean
    public Binding topicQueue02BindingInfoRoutingKey() {
        return BindingBuilder.bind(topicQueue02()).to(topicExchange())
                .with("lazy.#").noargs();
    }

}